<template>
	<view>
		<page-head :title="'报单管理'" :headtype="2" :gourl="`/pages/user/my`"></page-head>
		<view class="nav marginAuto">
			<view class="naveach" @click="navfun(1)" :class="navac == 1 ? 'navactive':''">待分配
				<view class="naveachx"></view>
			</view>
			<view class="naveach" @click="navfun(2)" :class="navac == 2 ? 'navactive':''">待审核
				<view class="naveachx"></view>
			</view>
			<view class="naveach" @click="navfun(3)" :class="navac == 3 ? 'navactive':''">已分配
				<view class="naveachx"></view>
			</view>
			<view class="naveach" @click="navfun(4)" :class="navac == 4 ? 'navactive':''">已取消
				<view class="naveachx"></view>
			</view>
		</view>
		<view class="orderlist">
			<view class="orderitem marginAuto" v-for="(item,index) in datas" :key="index">
				<view class="orderitemtop flex">
					<view class="orderitemtopname">{{ item.detail.goods_name }}</view>
					<view class="orderitemtopstatus" v-if="item.status == 1">待分配</view>
					<view class="orderitemtopstatus" v-if="item.status == 2">待审核</view>
					<view class="orderitemtopstatus" style="color: #3FC10C;" v-if="item.status == 3">已分配</view>
					<view class="orderitemtopstatus" style="color: #999999;" v-if="item.status == 4">已取消</view>
				</view>
				<view class="orderitemgoods flex">
					<view class="orderitemgoodsimg">
						<image v-if="!item.detail.goods_image" :src="apifun.serveimg + 'homegoods.png'" mode=""></image>
						<image v-if="item.detail.goods_image" :src="apifun.URLimg +item.detail.goods_image" mode=""></image>
					</view>
					<view class="orderitemgoodsmsg">
						<view class="orderitemtitle">报单数量(吨): <text style="font-weight: 600;">{{ item.num }}</text></view>
						<view class="orderitemmoney">单价(元): <text style="font-weight: 600;">{{ item.price }}</text></view>
					</view>
				</view>
				<view class="orderitemtime flex">
					<view class="orderitemtimemsg">报单时间：{{ item.create_time }}</view>
					<view class="orderitemtimebtn mainBg baiColor" @click="apifun.navigate('/pages/usermy/protxq','id='+item.id)">查看</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				apifun:this.apifun,
				navac:1,
				page:1,
				datas:[]
			};
		},
		onLoad(option) {
			this.navac = option.index || 1;
			this.initData();
		},
		methods: {
			initData(){
				let sendData = {
					page:this.page,
					limit:15,
					status:this.navac
				}
				this.apifun.unirequest('/user/user/getOrderList','post',sendData,(res)=>{
					// console.log(res)
					if(res.code === 200){
						let datas = res.data;
						if(datas.data.length <= 0){
							this.page--;
							return false
						}
						this.datas.push(...datas.data);
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			navfun(type){
				this.navac = type;
				this.page = 1;
				this.datas = [];
				this.initData();
			}
		},
		onPullDownRefresh() {
			this.page = 1;
			this.datas = [];
			this.initData();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			this.page++;
			this.initData()
		},
	};
</script>

<style scoped lang="scss">
	page{
		background: #FBFBFB;
		padding-bottom: 50rpx;
	}
	.nav {
		position:sticky;
		top: 0;
		width:90%;
		padding: 22rpx 5% 40rpx;
		display: flex;
		justify-content: space-between;
		background-color: #fff;
	
		.naveach {
			position: relative;
			color: #999999;
			font-size:30rpx;
			text-align: center;
	
			.naveachx {
				position: absolute;
				bottom: -10rpx;
				left: 50%;
				background: #fff;
				width: 50rpx;
				margin-left: -25rpx;
				height: 6rpx;
				border-radius: 100rpx;
				transition: background .3s;
			}
		}
	
		.navactive {
			color:#2340FF;
	
			.naveachx {
				background: #2340FF;
			}
		}
	}
	// 列表
	.orderitem{
		width: 630rpx;
		padding: 30rpx;
		background-color: #fff;
		margin-top: 20rpx;
		.orderitemtop{
			margin-bottom:40rpx;
			line-height: 50rpx;
			justify-content:space-between;
			.orderitemtopname{
				font-size:30rpx;
				color: #333;
				font-weight: 600;
			}
			.orderitemtopstatus{
				color: #E51818;
				font-size: 24rpx;
			}
		}
		.orderitemgoods{
			.orderitemgoodsimg{
				width: 140rpx;
				height: 140rpx;
				image{
					width: 140rpx;
					height: 140rpx;
					border-radius: 10rpx;
				}
			}
			.orderitemgoodsmsg{
				margin-left: 15rpx;
				line-height: 50rpx;
				.orderitemtitle{
					font-size:30rpx;
					color: #333;
					margin-top: 10rpx;
				}
				.orderitemmoney{
					font-size:30rpx;
					color: #333;
					margin-top: 10rpx;
				}
			}
		}
		.orderitemtime{
			height:60rpx;
			margin-top: 30rpx;
			justify-content: space-between;
			.orderitemtimemsg{
				color: #999999;
				line-height: 60rpx;
				font-size: 24rpx;
			}
			.orderitemtimebtn{
				width: 140rpx;
				height: 60rpx;
				line-height: 60rpx;
				text-align: center;
				border-radius: 10rpx;
				font-size:30rpx;
			}
		}
	}
</style>